package com.anywhere.freightman.car.dao;

import com.anywhere.freightman.car.model.CarModel;
import com.anywhere.freightman.car.model.DriverModel;
import com.anywhere.freightman.common.BaseMapper;
import com.anywhere.freightman.common.enumeration.DriverStatus;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface DriverDao extends BaseMapper<DriverModel> {

    DriverModel selectByIdentityNo(@Param("identityNo") String identityNo);

    DriverModel selectByTel(@Param("tel") String tel);

    @Select("select * from driver where company_id=#{companyId}")
    List<DriverModel> selectListByCompanyId(@Param("companyId") Long companyId);

    @Select("select * from driver where wx_app_id=#{wxAppId}")
    DriverModel selectByWxAppId(@Param("wxAppId") String wxAppId);

    List<CarModel> getCarList(@Param("driverId") Long driverId);

    @Select("update driver set wx_app_id=null where wx_app_id=#{wxAppId}")
    DriverModel deleteWxOpenId(@Param("wxAppId") String wxAppId);

    @Select("update driver set status=#{status} where id=#{driverId}")
    DriverModel changeStatus(@Param("driverId") long driverId,
                             @Param("status") DriverStatus status);

    @Select("update driver set password=#{password} where id=#{driverId}")
    DriverModel updatePwd(@Param("driverId") long driverId,
                          @Param("password") String password);


}
